//
//  MFriendViewController.m
//  NeusoftHBSJSober
//
//  Created by Apple-21 on 15/11/10.
//  Copyright (c) 2015年 com.neusoftsober. All rights reserved.
//

#import "MFriendViewController.h"
#import "MVIPCardService.h"
#import "MDDataBaseUtil.h"
#import "MyVipCardListModel.h"
#import "MViewUtil.h"
#import "MFriendDetailViewController.h"
@interface MFriendViewController ()<UITableViewDataSource, UITableViewDelegate> {

    MFriendDetailViewController *friendDetailVC;
}
- (IBAction)backAction:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UIView *titleView;
@property (weak, nonatomic) IBOutlet UITableView *myTableView;
@property (nonatomic, strong) NSMutableArray *vipCardListMutArray;
@end

@implementation MFriendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.titleView.backgroundColor = WHITESMOLKE;
}
- (void)viewWillAppear:(BOOL)animated {

    [self getVIPList];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.vipCardListMutArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *cellStr = @"VIP_CELL";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
        
        UILabel *salemenNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, SCREENWIDTH/3-20, 40)];
        salemenNameLabel.font = [UIFont fontWithName:nil size:13.0];
        salemenNameLabel.textAlignment = NSTextAlignmentCenter;
        salemenNameLabel.tag = 101;
        [cell.contentView addSubview:salemenNameLabel];
        
        UILabel *userNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREENWIDTH/3, 0, SCREENWIDTH/3, 40)];
        userNameLabel.font = [UIFont fontWithName:nil size:13.0];
        userNameLabel.textAlignment = NSTextAlignmentCenter;
        userNameLabel.tag = 102;
        [cell.contentView addSubview:userNameLabel];
        
        UILabel *isUserLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREENWIDTH/3*2, 0, SCREENWIDTH/3, 40)];
        isUserLabel.font = [UIFont fontWithName:nil size:13.0];
        isUserLabel.textAlignment = NSTextAlignmentCenter;
        isUserLabel.tag = 103;
        [cell.contentView addSubview:isUserLabel];
    }
    MyVipCardListModel *model = [[MyVipCardListModel alloc]init];
    model = [self.vipCardListMutArray objectAtIndex:indexPath.row];
    
    ((UILabel *)[cell.contentView viewWithTag:101]).text = model.salemanName;
    ((UILabel *)[cell.contentView viewWithTag:102]).text = model.UserName;
    if ([model.isUse integerValue]) {
        ((UILabel *)[cell.contentView viewWithTag:103]).text = @"是";
    } else {
        ((UILabel *)[cell.contentView viewWithTag:103]).text = @"否";
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    MyVipCardListModel *model = [[MyVipCardListModel alloc]init];
    model = [self.vipCardListMutArray objectAtIndex:indexPath.row];
    friendDetailVC = [[MFriendDetailViewController alloc]init];
    
    friendDetailVC.vipCardListModel = model;
    friendDetailVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:friendDetailVC animated:YES completion:nil];
    
}
- (IBAction)backAction:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)getVIPList {
    [[MViewUtil instance] showLoadingText:@"正在加载..." targetView:self.view];
    [[MVIPCardService sharedClient]getMyVipCardWithUserID:[[MDDataBaseUtil userID]integerValue] isFriend:@"true" isUse:@"" completion:^(NSMutableArray *result){
        [[MViewUtil instance] hideLoadingTextFromTargetView:self.view];
        self.vipCardListMutArray = [NSMutableArray arrayWithArray:result];
        [self.myTableView reloadData];
    } failure:^(NSString *error){
        
        
    }];
}
@end
